package com.company.堆栈队列;

import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * @author Administrator
 */
public class 数据流中的中位数 {
    List<Integer> insets = new ArrayList<>();

    public void Insert(Integer num) {
        insets.add(num);
    }

    public Double GetMedian() {
        Collections.sort(insets);
        Double result = 0.0;
        if (insets.size() % 2 == 0) {
            if (insets.size() <= 2) {
                int index1 = insets.size() / 2 - 1;
                int index2 = insets.size() / 2;
                result = (Double.valueOf(insets.get(index1)) + Double.valueOf(insets.get(index2))) / 2;
            } else {
                result = (((Double.valueOf(insets.get(insets.size() / 2 - 1))) + Double.valueOf((insets.get(insets.size() / 2 + 1)))) / 2);
            }
        } else {
            result = Double.valueOf(insets.get(insets.size() / 2));
        }
        return result;
    }

    public static void main(String[] args) {
        数据流中的中位数 num = new 数据流中的中位数();
        Scanner scanner = new Scanner(System.in);
        BufferedInputStream bis = new BufferedInputStream(System.in);
        while (bis != null) {
            num.Insert(scanner.nextInt());
            Double aDouble = num.GetMedian();
            System.out.println(aDouble);
        }
    }
}
